package designPattern.behavioralPattern.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wei.zhao
 * @description: 具体中介者
 * @date 2021年12月23日 12:55
 */
public class ConcreteMediator implements Mediator {

    private List<Colleague> colleagues = new ArrayList<>();

    @Override
    public void register(Colleague colleague) {
        if (!colleagues.contains(colleague)) {
            colleagues.add(colleague);
            colleague.setMediator(this);
        }
    }

    @Override
    public void relay(Colleague cl) {
        for (Colleague colleague : colleagues) {
            if (!colleague.equals(cl)) {
                colleague.receive();
            }
        }
    }

}
